package com.objetdirect.gwt.umldrawer.server.services;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.objetdirect.gwt.umldrawer.server.dao.DiagramDao;
import com.objetdirect.gwt.umldrawer.shared.dto.DiagramDto;
import com.objetdirect.gwt.umldrawer.shared.dto.ProjectDto;
import com.objetdirect.gwt.umldrawer.shared.services.DiagramService;

@Service("diagramService")
public class DiagramServiceImpl implements DiagramService {

	@Autowired
	private DiagramDao diagramDAO ;
	
	@PostConstruct
	public void init() {
	}
	
	@PreDestroy
	public void distroy() {
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void addDiagram(int projectId, String diagramName,
			String diagramType, String diagramPath) throws Exception {
		
		ProjectDto project = new ProjectDto(projectId);
		DiagramDto diagram = new DiagramDto(diagramName, diagramType, diagramPath, project);
		diagramDAO.persist(diagram);
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<DiagramDto> getDiagrams(int projectId) throws Exception {
		
		return null;
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void removeDiagram(int projectid, String diagramName)
			throws Exception {
		
		
	}
	
}
